package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.db.domain.system.MpClient;
import com.ruoyi.db.domain.system.MpClientRaiseRecord;
import com.ruoyi.db.domain.system.PcRaise;
import com.ruoyi.db.mapper.system.MpClientMapper;
import com.ruoyi.db.mapper.system.MpClientRaiseRecordMapper;
import com.ruoyi.db.mapper.system.PcRaiseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.service.IMpClientRaiseRecordService;

import javax.transaction.Transactional;

/**
 * 用户参与众筹活动记录Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-08-03
 */
@Service
@Transactional(rollbackOn = Exception.class)
public class MpClientRaiseRecordServiceImpl implements IMpClientRaiseRecordService 
{
    @Autowired
    private MpClientRaiseRecordMapper mpClientRaiseRecordMapper;
    @Autowired
    private MpClientMapper mpClientMapper;
    @Autowired
    private PcRaiseMapper pcRaiseMapper;

    /**
     * 查询用户参与众筹活动记录
     * 
     * @param id 用户参与众筹活动记录主键
     * @return 用户参与众筹活动记录
     */
    @Override
    public MpClientRaiseRecord selectMpClientRaiseRecordById(Long id)
    {
        return mpClientRaiseRecordMapper.selectMpClientRaiseRecordById(id);
    }

    /**
     * 查询用户参与众筹活动记录列表
     * 
     * @param mpClientRaiseRecord 用户参与众筹活动记录
     * @return 用户参与众筹活动记录
     */
    @Override
    public List<MpClientRaiseRecord> selectMpClientRaiseRecordList(MpClientRaiseRecord mpClientRaiseRecord)
    {
        List<MpClientRaiseRecord> list = mpClientRaiseRecordMapper.selectListByTime(mpClientRaiseRecord);
        for (MpClientRaiseRecord raiseRecord:list) {

            if(raiseRecord.getIsAble()==1&&raiseRecord.getIsOver()==0){
                raiseRecord.setRaiseStatus("进行中");
            }
            if(raiseRecord.getIsAble()==1&&raiseRecord.getIsOver()==1){
                raiseRecord.setRaiseStatus("已经结束");
            }
            if(raiseRecord.getIsAble()==0){
                raiseRecord.setRaiseStatus("已失效");
            }
            raiseRecord.setIsSuccess(raiseRecord.getIsSuccess());
        }
        return list;
    }

    /**
     * 新增用户参与众筹活动记录
     * 
     * @param mpClientRaiseRecord 用户参与众筹活动记录
     * @return 结果
     */
    @Override
    public int insertMpClientRaiseRecord(MpClientRaiseRecord mpClientRaiseRecord)
    {
        return mpClientRaiseRecordMapper.insertMpClientRaiseRecord(mpClientRaiseRecord);
    }

    /**
     * 修改用户参与众筹活动记录
     * 
     * @param mpClientRaiseRecord 用户参与众筹活动记录
     * @return 结果
     */
    @Override
    public int updateMpClientRaiseRecord(MpClientRaiseRecord mpClientRaiseRecord)
    {
        return mpClientRaiseRecordMapper.updateMpClientRaiseRecord(mpClientRaiseRecord);
    }

    /**
     * 批量删除用户参与众筹活动记录
     * 
     * @param ids 需要删除的用户参与众筹活动记录主键
     * @return 结果
     */
    @Override
    public int deleteMpClientRaiseRecordByIds(Long[] ids)
    {
        return mpClientRaiseRecordMapper.deleteMpClientRaiseRecordByIds(ids);
    }

    /**
     * 删除用户参与众筹活动记录信息
     * 
     * @param id 用户参与众筹活动记录主键
     * @return 结果
     */
    @Override
    public int deleteMpClientRaiseRecordById(Long id)
    {
        return mpClientRaiseRecordMapper.deleteMpClientRaiseRecordById(id);
    }
}
